﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace TextAnalyzer
{
    /// <summary>
    /// ExportDialog.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class ExportDialog : Window
    {
        private TextViewModel mViewModel = null;
        public ExportDialog()
        {
            InitializeComponent();

            if (null == mViewModel) mViewModel = TextViewModel.GetInstance();
            this.DataContext = mViewModel;
        }
        private void OnClickButtonExport(object sender, RoutedEventArgs e)
        {
            try
            {
                Microsoft.Win32.SaveFileDialog _dialog = new Microsoft.Win32.SaveFileDialog();
                if (true == (bool)_dialog.ShowDialog())
                {
                    List<KeyViewModel> _models = null;
                    if (null != listBoxSelection.SelectedItems)
                    {
                        _models = new List<KeyViewModel>();
                        if (0 < listBoxSelection.SelectedItems.Count)
                        {
                            foreach (object _item in listBoxSelection.SelectedItems)
                            {
                                KeyViewModel _view = _item as KeyViewModel;
                                if (null != _view) _models.Add(_view);
                            }
                        }
                    }
                    Exporter _exporter = new Exporter();
                    _exporter.Export(_models, _dialog.FileName);
                    MessageBox.Show("출력을 끝냈습니다.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "오류");
            }
        }
    }
}
